from tools_algorithm import *


class Solution:
    def timeRequiredToBuy(self, tickets: List[int], k: int) -> int:
        ans = 0
        for i, v in enumerate(tickets):
            ans += v if v < tickets[k] else tickets[k] - 1 if i > k else tickets[k]
        return ans
